<?php
/**
 * Created by JetBrains PhpStorm.
 * User: GMC
 * Date: 10/3/13
 * Time: 2:20 PM
 * To change this template use File | Settings | File Templates.
 */

class WidgetGuestBook extends CWidget {
    public $guestBooks, $owner_id, $total;

    public function init() {
        Yii::app()->language = 'vi';
        $criteria = new CDbCriteria();
        $criteria->select = '*';
        $criteria->condition = 'owner_id = :id';
        $criteria->params = array(':id' => $this->owner_id);
        $criteria->order = 'guest_book_id DESC';

        $this->guestBooks = new CActiveDataProvider('GuestBook', array(
            'criteria' => $criteria,
            'pagination' => array('pageSize' => 5)
        ));

        $this->total = GuestBook::model()->count($criteria);
    }

    public function run() {
        return CWidget::render('widgetGuestBook', array('model' => $this->guestBooks, 'total' => $this->total, 'owner_id' => $this->owner_id));
    }
}